package com.zjj.wangluo.lianxi.tcp03;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author zhoujunjie
 * @desc TODO
 * @date
 *
 * 读 & 写
 */
public class TCPClient {

    public static void main(String[] args) {
        System.out.println("---------客户端---------");
        try (
                //1.创建客户端
                Socket s = new Socket("172.21.111.180", 8888);
                //读
                BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
                //写
                PrintWriter pw = new PrintWriter(s.getOutputStream());
                Scanner sc = new Scanner(System.in);
        ){
            while (true) {
                //先写
                System.out.println("客户端说：");
                String str = sc.nextLine();
                pw.println(str);
                pw.flush();

                if(str.equals("886")){
                    break;
                }

                //再读
                String string = br.readLine();
                System.out.println("客户端读："+string);

            }


        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
